<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
   xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
   xmlns:f="http://xmlns.jcp.org/jsf/core"
   xmlns:h="http://xmlns.jcp.org/jsf/html"
   xmlns:p="http://primefaces.org/ui"
   xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
   xmlns:pe="http://primefaces.org/ui"
   template="/WEB-INF/templates/business/buyer/template.xhtml">
   
   	<f:metadata>
	   	<f:viewParam name="bulletinId" value="#{bulletinHome3.id}"></f:viewParam>
   	</f:metadata>
   	<ui:define name="buyer_head">
   		<style type="text/css">
   			   			
   		</style>
		
		<script>
			var websocket;
			function createWs() {
    			if (typeof(WebSocket) !== "undefined") {
					var host = window.location.host;
					var wsUri = "ws://" + host + "/bulletinEnd/#{bulletinHome3.id}";
					websocket = new WebSocket(wsUri);
					websocket.onopen = function () {
						console.info('opened');
					};
					websocket.onclose = function () {
						console.info('closed');
					};
			        websocket.onerror = function(evt) { 
			            onError(evt);
			            createWs();
			        }; 
					websocket.onmessage = function (evt) {
						console.info( 'onMessage fired' );
						refreshBids();
					};
    			} else {
					alert("您的浏览器不支持Websocket，请更换浏览器，推荐使用Chrome、Firefox、IE11.0及以上版本。");
				}
			} 
			 
		    function onError(evt) { 
		        $('#websocketError').css("display", "block");
		    }
			
			$(function () {
				createWs();
			});
		</script>
   		
   	</ui:define>
   	<ui:define name="buyer_content">
   		
			
		<h2 id="websocketError" style="color: red; font-weight: bold; display: none;">您的网络连接已经断开，如果需要继续观察选取结果请刷新。</h2>
   
		<h:form id="editForm"  >         
			<h:inputHidden value="#{bulletinHome3.id}" />
			<p:panel id="panel" header="公告信息" style="margin-bottom:10px;">
		       <p:messages id="messages" closable="true"><p:autoUpdate/></p:messages>
		         <ui:include src="/WEB-INF/templates/business/bulletinBasicInfo.xhtml" />
			</p:panel>
	
			<p:panel id="bidPanel" header="实时报价清单" style="margin-bottom:10px;">
				<h1>当前平均价格：#{bulletinHome3.instance.average}</h1>
				
				<p:dataTable value="#{bulletinHome3.instance.pricedTrades}" var="_trade">
				
					<p:column headerText="中介机构名称">
						<h:outputText value="#{_trade.supplier.cnname}" />
					</p:column>
					
					<p:column headerText="报价">
						<h:outputText value="#{_trade.offer}" />
					</p:column>
					
				</p:dataTable>
			</p:panel>
			
			<p:remoteCommand action="#{bulletinHome3.refresh()}" update="bidPanel" name="refreshBids">
			</p:remoteCommand>
			
		</h:form>
		
		
   	</ui:define>
</ui:composition>
